/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-03
 * Time: 23:44
 */
class Solution2 {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length,sum = 0;

        for(int i = 0; i < n-1; i++) {
            int index = timeSeries[i]+duration;
            if(index <= timeSeries[i+1]) {
                sum += duration;
            }else {
                sum += timeSeries[i+1]-timeSeries[i];
            }
        }
        return sum+duration;
    }
}
